/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Data;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Administrator
 */
public class ThematicData {
    private String[][] originData;
    /**
     * 构造函数
     */
    public ThematicData(){
        originData=null;
    }
    
    public ThematicData(String[][] excelData)
    {
        originData=excelData;
    }
    /**
    *
     * @return 返回第一行属性名
    */
    public ArrayList<String> GetTitleString()
    {
        ArrayList<String> Attribute=new ArrayList<>();
        for(int i=0;i<originData[0].length;i++)
        {
            Attribute.add(originData[0][i]);
        }
        return Attribute;
    }
    public ArrayList<String> GetTitleString(List<Integer> cols){
        ArrayList<String> Attribute=new ArrayList<>();
        for(int i=0;i<originData[0].length;i++)
        {
            if(cols.contains(i)){
                Attribute.add(originData[0][i]);
            }
        }
        return Attribute;
    }
    /**
     * 
     * @param rowname 行名
     * @return 返回查询行的所有数据
     */
    public ArrayList<String> GetRowString(String rowname)
    {
        ArrayList RowData=new ArrayList<>();
        for(int i=0;i<originData.length;i++)
        {
            if(originData[i][0].equals(rowname));
            {
                for(int j=0;j<originData[i].length;j++)
                {
                    RowData.add(originData[i][j]);
                }
                break;
            }
        }
        return RowData;
    }
    
    public ArrayList<String> GetColString(String colname)
    {
        ArrayList ColData=new ArrayList<>();
        for(int i=0;i<originData[0].length;i++)
        {
            if(originData[0][i].equals(colname))
            {
                for(int j=1;j<originData.length;j++)
                {
                    ColData.add(originData[j][i]);
                } 
                break;
            }
        }
        return ColData;
    }
    
    public ArrayList<String> GetColString(int col)
    {
        ArrayList ColData=new ArrayList<>();
        if(col>=0&&col<originData.length)
        {
            for(int i=0;i<originData.length;i++)
            {
                ColData.add(originData[i][col]);
            }
        }
        return ColData;
    }
    
    public ArrayList<ArrayList<String>> GetMutiColStringByName(ArrayList<String> cols){
        ArrayList<ArrayList<String>> mutiCols;
        mutiCols = new ArrayList<>();
        for(int i=0;i<cols.size();i++){
            ArrayList<String> col=GetColString(cols.get(i));
            mutiCols.add(col);
        }
        return mutiCols;
    }
    
     public ArrayList<ArrayList<String>> GetMutiColStringById(ArrayList<Integer> cols){
        ArrayList<ArrayList<String>> mutiCols;
        mutiCols = new ArrayList<>();
        for(int i=0;i<cols.size();i++){
            ArrayList<String> col=GetColString(cols.get(i));
            mutiCols.add(col);
        }
        return mutiCols;
    }
    
    /**
     *
     * @param colname
     * @return
     */
    public ArrayList<Double> GetColdouble(String colname)
    {
        ArrayList ColData=new ArrayList<>();
        for(int i=0;i<originData[0].length;i++)
        {
            if(originData[0][i].equals(colname))
            {
                for(int j=1;j<originData.length;j++)
                {
                    ColData.add(Double.parseDouble(originData[j][i]));
                } 
                break;
            }
        }
        return ColData;
    }
    
    public ArrayList<Double> GetColdouble(int col)
    {
        ArrayList ColData=new ArrayList<>();
        if(col>=0&&col<originData.length)
        {
            for(int i=1;i<originData.length;i++)
            {
                ColData.add(Double.parseDouble(originData[i][col]));
            }
        }
        return ColData;
    }
    
    public ArrayList<Integer> GetColInteger(int col){
        ArrayList<Integer> ColData=new ArrayList<>();
        if(col>=0&&col<originData.length)
        {
            for(int i=1;i<originData.length;i++)
            {
                ColData.add(Integer.parseInt(originData[i][col]));
            }
        }
        return ColData;
    }
    
    public ArrayList<ArrayList<Double>> GetMutiColdoubleByName(List<String> colsname){
        ArrayList<ArrayList<Double>> mutiCols;
        mutiCols = new ArrayList<>();
        for(int i=0;i<colsname.size();i++){
            ArrayList<Double> col=GetColdouble(colsname.get(i));
            mutiCols.add(col);
        }
        return mutiCols;
    }
    //获取多列数据，并转置
    public ArrayList<List<Double>> GetMutiColdoubleByNameTS(List<String> colsname){
        ArrayList<List<Double>> mutiCols;
        mutiCols = new ArrayList<>();
        for(int i=1;i<originData.length;i++){
            mutiCols.add(GetRowdoubleByName(i,colsname));
        }
        return mutiCols;
    }
    
     public ArrayList<ArrayList<Double>> GetMutiColdoubleById(ArrayList<Integer> cols){
        ArrayList<ArrayList<Double>> mutiCols;
        mutiCols = new ArrayList<>();
        for(int i=0;i<cols.size();i++){
            
            ArrayList<Double> col=GetColdouble(cols.get(i));
            mutiCols.add(col);
        }
        return mutiCols;
    }
     //获取第i行，指定cols列里的数据，返回list数据。
    public ArrayList<Double> GetRowdoubleById(int i,ArrayList<Integer> cols){
         ArrayList<Double> row=new ArrayList<>();
         for(int j=0;j<originData[i].length;j++){
             if(cols.contains(j)){
                 row.add(Double.parseDouble(originData[i][j]));
             }
         }
         return row;
     }
    
    public ArrayList<Double> GetRowdoubleByName(int i,List<String> colsname){
         ArrayList<Double> row=new ArrayList<>();
         List<String> title=GetTitleString();
         for(int j=0;j<originData[i].length;j++){
             if(colsname.contains(title.get(j))){
                 row.add(Double.parseDouble(originData[i][j]));
             }
         }
         return row;
     }
}
